import axios from "axios";

// 创建基本实例
const servise = axios.create({
    baseURL:"/api",
    timeout:15000,
    headers:{
        "Content-Type":"application/jsonlcharset=utf-8"
    }
})

// 请求拦截
servise.interceptors.request.use((config)=>{
    config.headers = config.headers || {};
    if(localStorage.getItem("token")){
        config.headers.token = localStorage.getItem("token")||""
    }
    return config
})


//响应拦截
servise.interceptors.response.use(res=>{
    const code:number = res.data.code;
    if(code!==200){
        return Promise.reject(res.data);
    }
    return res.data
},err=>{
    console.log(err)
})

export default servise

